﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace eProject.Model
{
    /// <summary>
    /// This class represents task data
    /// </summary>
    public class Task
    {       
        private string _name;
        public string Name
        {
            get{ return _name;}
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value", "Name cannot be null");
                }
                _name = value;
                InvokeTaskChanged(this);
            }
        }

        private string _description;
        public string Description
        {
            get { return _description; }
            set
            {                
                _description = value ?? "";
                InvokeTaskChanged(this);
            }            
        }

        private long _duration;//TODO think about this property
        public long Duration
        {
            get { return _duration; }
            set
            {
                if (value <= 0)
                {
                    throw new ArgumentException("Duration must be greater than zero");
                }
                _duration = value;
                InvokeTaskChanged(this);
            }
        }
       // private long Id{ get{ return Id;}}

        public Task(string name, string description, long duration)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (description == null)
            {
                throw new ArgumentNullException("description");
            }
            if (name == "")
            {
                throw new ArgumentException("The name must not be empty");
            }

            if (duration < 0)
            {
                throw new ArgumentException("The duration must be greater than zero");
            }
           
            Name = name;
            Description = description;
            Duration = duration;
        }

       
        public delegate void TaskChangedEventHandler(Task task);

        public event TaskChangedEventHandler TaskChanged;

        private void InvokeTaskChanged(Task task)
        {
            var changed = TaskChanged;
            if (changed != null) changed(task);
        }
       
    }
}
